//
//  ContrastDingCell.swift
//  QMContrastTableView
//
//  Created by 戴泉明 on 2021/4/25.
//

import Foundation
import UIKit

class DingItem: UIView {
    var titleLabel = UILabel()
    
    class func createView() ->DingItem {
        let view = DingItem()
//        view.titleLabel.backgroundColor = UIColor.white
        view.titleLabel.textColor = UIColor.black
        view.addSubview(view.titleLabel)
        view.titleLabel.snp.makeConstraints { (make) in
            make.left.top.bottom.equalTo(view)
            make.width.equalTo(CONTRAST_ITEM_WIDTH)
        }
        view.titleLabel.text = " - "
        view.titleLabel.textColor = UIColor.init(ts_hexString: "#202629")
        view.titleLabel.font = UIFont.systemFont(ofSize: 12)
        view.titleLabel.textAlignment = .center
        view.titleLabel.numberOfLines = 0
        view.layer.borderWidth = 0.5
        view.layer.borderColor = UIColor.init(ts_hexString: "#E3E4E5").cgColor
        return view
    }
}

class ContrastDingCell: UITableViewCell {
    
    var DingItems:[DingItem] = []
    
    class func cellWithTableView(tableView:UITableView) -> ContrastDingCell {
        let id:String = "ContrastDingCell"
        var cell = tableView.dequeueReusableCell(withIdentifier: id) as? ContrastDingCell
        if  cell == nil {
            cell = ContrastDingCell()
            cell?.backgroundColor = UIColor.white
        }
        cell?.selectionStyle = .none
        return cell ?? ContrastDingCell()
    }
    
    func setDatas(datas:[ContrastModel], indexPath:IndexPath) {
        
        for item in DingItems.reversed() {
            item.removeFromSuperview()
        }
        
        for (index,_) in datas.enumerated() {
            let item = DingItem.createView()
            contentView.addSubview(item)
            DingItems.append(item)
            item.snp.makeConstraints { (make) in
                make.left.equalTo(CONTRAST_ITEM_WIDTH * CGFloat(index))
                make.top.bottom.equalTo(contentView)
                make.width.equalTo(CONTRAST_ITEM_WIDTH)
            }
        }
        
        //没数据
        if datas.count == 0 {
            return
        }
        let item = datas.first!
        DingItems[0].titleLabel.text = item.groupParamsViewModelList[indexPath.section].paramList[indexPath.row].paramValue
    }
    
}

